package com.xhh.nphm.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xhh.nphm.system.domain.TagLibrary;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface TagDao extends BaseMapper<TagLibrary> {

    /**
     * 查询标签库数据
     * 通过标签名模糊搜索
     * @param tagEntity 标签库实体类
     * @return
     */
    @Select("select PkId pkid,tag_name tagName,create_time createTime,update_time updateTime,is_del isDel,is_common isCommon from tm_tag_library where is_del = 0 " +
            "[[and tag_name =#{tag.tagName}]]")
    List<TagLibrary> selectTagListJson(@Param("tag") TagLibrary tagEntity);

    /**
     * 查询常用标签，展示在添加页面
     * is_common = 1
     * @return
     */
    @Select("select PkId as tagNo, tag_name as tagName from tm_tag_library " +
            "where is_del = 0 and is_common = 1")
    List<Map<String,Object>> selectCommonTag();

    /**
     * 查询所有标签名，用于检索时自动补全
     * @return
     */
    @Select("select tag_name from tm_tag_library " +
            "where is_del = 0")
    List<String> autoComplete();

    /**
     * 通过标签名查询标签编号
     * @param tagName
     * @return
     */
    @Select("select PkId from tm_tag_library where tag_name=#{tagName}")
    Long selectByTagName(String tagName);
}
